package org.qianji.goosql.cond;

import java.util.List;
import java.util.Map;

/**
 * 非查询条件。
 * 
 * @author gmz
 * 
 */
public class Not extends AbstractCondition {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3381210617568212928L;

	private Condition cond;

	/**
	 * 构造非查询条件。
	 * 
	 * @param cond
	 *            {@link Condition} 查询条件
	 */
	public Not(Condition cond) {
		super();
		if (cond == null) {
			throw new NullPointerException("cond can't be null");
		}
		this.cond = cond;
	}

	/**
	 * 获取旧查询条件。
	 * 
	 * @return {@link Condition} 查询条件
	 */
	public Condition getCond() {
		return cond;
	}

	@Override
	public String toSql() {
		StringBuffer cond = new StringBuffer();
		cond.append("NOT(").append(getCond().toSql()).append(")");
		return cond.toString();
	}

	@Override
	public List<Object> getPlacedParameters() {
		return cond.getPlacedParameters();
	}

	@Override
	public Map<String, Object> getNamedParameters() {
		return cond.getNamedParameters();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null || !(obj instanceof Not)) {
			return false;
		}
		if (cond.equals(((Not) obj).getCond())) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hc = 37 * 17 + cond.hashCode();
		return hc;
	}

	@Override
	public String toString() {
		return toSql();
	}

}
